package com.lt.basic.project.pojo.entity.mino.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lt.basic.project.common.uid.Id;
import com.lt.basic.project.common.util.StringUtils;
import com.lt.basic.project.pojo.validate.mino.user.UserAuthCreateValidate;
import com.lt.basic.project.pojo.validate.mino.user.UserAuthUpdateValidate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 用户授权表(basic_user_auth)数据实体
 * @author ：LT
 * @Created in : 2023-11-27
 */

@Data
@ApiModel(value = "UserAuth对象", description = "用户授权表(basic_user_auth)表")
public class UserAuth implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * Openid
     */
    private String openid;

    /**
     * Unionid
     */
    private String unionid;

    /**
     * 客户端类型: [1=微信小程序, 2=微信公众号, 3=手机H5, 4=电脑PC, 5=苹果APP, 6=安卓APP]
     */
    private Integer terminal;

    /**
     * 创建时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 更新时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;


    /**
    * 添加数据
    */
    public void create(UserAuthCreateValidate createValidate) {
        setId(Id.getId());
        setUserId(createValidate.getUserId());
        setOpenid(createValidate.getOpenid());
        setUnionid(createValidate.getUnionid());
        setTerminal(createValidate.getTerminal());
        setCreateTime(new Date());
    }

    /**
    * 编辑数据
    */
    public void modify(UserAuthUpdateValidate updateValidate) {
        if (StringUtils.isNotObj(updateValidate.getUserId())) {
            setUserId(updateValidate.getUserId());
        }
        if (StringUtils.isNotObj(updateValidate.getOpenid())) {
            setOpenid(updateValidate.getOpenid());
        }
        if (StringUtils.isNotObj(updateValidate.getUnionid())) {
            setUnionid(updateValidate.getUnionid());
        }
        if (StringUtils.isNotObj(updateValidate.getTerminal())) {
            setTerminal(updateValidate.getTerminal());
        }
        setUpdateTime(new Date());
    }

}